/**
 * @file STL_MysqlQueryResult.h
 * @author Derek Liu (yjkhtddx@sina.com)
 * @brief 
 * @version 0.1
 * @date 2020-10-14
 * 
 * @copyright Copyright Sci-Tech Laboratories (c) 2020
 * 
 */

#ifndef _STL_MYSQL_QUERY_RESULT_H_
#define _STL_MYSQL_QUERY_RESULT_H_

#include <mysql/mysql.h>
#include <string>
#include <vector>
#include "STL_Json.h"

namespace STL
{
    class STL_MysqlConnection;
    class STL_MysqlQueryResult
    {
    public:
        STL_MysqlQueryResult() : insert_id(0), affected_rows(0), sql_state(""), info(""), error_number(0), error_info(""), field_count(0)
        {
            fields.clear();
            string_table.clear();
        }

    public:
        int getRowCount() { return string_table.size(); }
        int getColumnCount() { return fields.size(); };
        std::string getField(int column) { return fields[column]; }
        std::string getElement(int row, int column) { return string_table[row][column]; }

        friend class STL_MysqlConnection;

    public:
        void addField(const std::string field) { fields.push_back(field); };

    public:
        my_ulonglong insert_id;
        my_ulonglong affected_rows; // (my_ulonglong)-1 为无效值
        std::string sql_state;
        std::string info;
        unsigned int error_number;
        std::string error_info;
        unsigned int field_count;
        std::vector<std::string> fields;
        std::vector<std::vector<std::string> /**/> string_table; // 注意尖括号套用需要加空格 < <> >
    public:
        JSONCPP::Value json_table;
    };
} //STL

#endif //_STL_MYSQL_QUERY_RESULT_H_